package examination;

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNextInt()) {
            long N = scanner.nextLong();
            if (N >= 0) {
                long[] fib = new long[100];
                fib[0] = 0;
                fib[1] = 1;
                for (int i = 2; i < 100 ;i++) {
                    fib[i] = fib[i - 1] + fib[i - 2];
                }
                int index = 0;
                while (fib[index] < N) {
                    index++;
                }
                if (fib[index] == N) {
                    System.out.println(0);
                }else {
                    long ret1 = fib[index] - N;
                    long ret2 = N - fib[index - 1];
                    long ret = ret1 < ret2 ? ret1 : ret2;
                    System.out.println(ret);
                }
            }

        }
    }
}
//    public static void main(String[] args) {
//        Scanner scanner = new Scanner(System.in);
//        Set<String> set = new HashSet<>();
//        while (scanner.hasNext()) {
//            String string = scanner.nextLine();
//            String[] strings = string.split(" ");
//            for (int i = 0; i < strings.length; i++) {
//                set.add(strings[i]);
//            }
//        }
//        System.out.println(set.size());
//        set.clear();
//    }

